package com.sky.controller.user;


import com.sky.entity.FirstCategory;
import com.sky.result.Result;
import com.sky.service.CategoryService;

import com.sky.service.impl.CategoryServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "C端-分类的相关接口")
@Slf4j
@RequestMapping("/user/category")
public class CategoryController {
    @Autowired
    private CategoryServiceImpl categoryService;
    // 查询时自动缓存，key为方法参数，value为返回值
    @Cacheable(value = "category", key = "'all'", unless = "#result == null")
    @GetMapping("/list")
    @ApiOperation("获取分类信息")
    public Result<List<FirstCategory>> list() {
        List<FirstCategory> list = categoryService.categories();
        return Result.success(list);
    }
}
